﻿using Microsoft.AspNetCore.Components.Forms;
using Microsoft.Extensions.Options;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quickly.Certs.UnitTests
{
    public class MockData
    {
        public static string? EnvironmentVariable(string name) => Environment.GetEnvironmentVariable(name);

        public static IOptionsMonitor<AlibabaCloudAccessKey> AlibabaCloudAccessKeyMonitor() => AlibabaCloudAccessKeyMonitor(
            EnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID") ?? "",
            EnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET") ?? "");

        public static IOptionsMonitor<AlibabaCloudAccessKey> AlibabaCloudAccessKeyMonitor(string id, string secret)
        {
            var mock = new Mock<IOptionsMonitor<AlibabaCloudAccessKey>>();

            mock.Setup(x => x.CurrentValue).Returns(new AlibabaCloudAccessKey(id, secret));

            return mock.Object;
        }

        public static IOptions<AlibabaCloudAccessKey> AlibabaCloudAccessKey()
            => AlibabaCloudAccessKey(
                EnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID") ?? "",
                EnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET") ?? "");

        public static IOptions<AlibabaCloudAccessKey> AlibabaCloudAccessKey(string id, string secret)
        {
            var mock = new Mock<IOptions<AlibabaCloudAccessKey>>();

            mock.Setup(x => x.Value).Returns(new AlibabaCloudAccessKey(id, secret));

            return mock.Object;
        }

        public static IOptions<AlibabaCloudEndpoint> AlibabaCloudEndpoint()
            => AlibabaCloudEndpoint(EnvironmentVariable("ALIBABA_CLOUD_ENDPOINT_ALIDNS") ?? "");

        public static IOptions<AlibabaCloudEndpoint> AlibabaCloudEndpoint(string address)
        {
            var mock = new Mock<IOptions<AlibabaCloudEndpoint>>();

            mock.Setup(x => x.Value).Returns(new Certs.AlibabaCloudEndpoint(address));

            return mock.Object;
        }

        public static IOptionsMonitor<AlibabaCloudEndpoint> AlibabaCloudEndpointMonitor() 
            => AlibabaCloudEndpointMonitor(EnvironmentVariable("ALIBABA_CLOUD_ENDPOINT_ALIDNS") ?? "");

        public static IOptionsMonitor<AlibabaCloudEndpoint> AlibabaCloudEndpointMonitor(string address)
        {
            var mock = new Mock<IOptionsMonitor<AlibabaCloudEndpoint>>();

            mock.Setup(x => x.CurrentValue).Returns(new AlibabaCloudEndpoint(address));

            return mock.Object;
        }
    }
}
